<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

class CreateUserWithdrawsTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('user_withdraws', function (Blueprint $table) {
            $table->id();
            $table->bigInteger('user_id')->unsigned()->comment('用户ID');
            $table->char('wallet_type', 50)
                ->default(\App\Constant\Enum::WALLET_TYPE_REWARD)
                ->index()
                ->comment('账户类型');
            $table->decimal('money', 8, 2)
                ->default(0)
                ->comment('提现金额');
            $table->integer('exchange_rate')
                ->default(0)
                ->comment('兑换比例');
            $table->bigInteger('amount')
                ->default(0)
                ->comment('兑换金币数量');
            $table->bigInteger('before_coins')
                ->default(0)
                ->comment('变动前金币数量');
            $table->bigInteger('after_coins')
                ->default(0)
                ->comment('变动后金币数量');
            $table->char('status', 50)
                ->default(\App\Constant\Enum::WITHDRAW_STATUS_PENDING)
                ->index()
                ->comment('状态');
            $table->bigInteger('operator_id')
                ->default(0)
                ->comment('操作人');
            $table->timestamp('applied_at')
                ->nullable()
                ->comment('提现申请时间');
            $table->timestamp('audited_at')
                ->nullable()
                ->comment('审核时间');
            $table->string('remark')->default('')
                ->comment('备注');
            $table->timestamps();
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists('user_withdraws');
    }
}
